package day5;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.Scanner;

public class RentCompany {
    Scanner input = new Scanner(System.in);
    private String name;
    private String adress;
    private String number;



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }


    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }



    public RentCompany( String name, String adress, String number) {
        this.name = name;
        this.adress = adress;
        this.number = number;

    }

    public void show() {
        System.out.println("欢迎光临" + name + "租车公司，本公司地址在" + adress + "电话号码是" + number );
    }

    Vehicle[] vehicles = new Vehicle[20];//机动车数组
    Rent[] rent = new Rent[100];//租赁记录数组
    int count = 8;//车数量
    int sum=0;//租车记录

    public RentCompany() {
        vehicles[0] = new Car("皖A88888", "大众", 800, 5, "当前可租", "途岳");
        vehicles[1] = new Car("皖A55555", "奇瑞", 200, 5, "当前可租", "瑞虎");
        vehicles[2] = new Car("皖A67465", "别克", 500, 5, "当前可租", "GL8");
        vehicles[3] = new Car("皖A66666", "保时捷", 900, 5, "当前可租", "911");
        vehicles[4] = new Bus("皖A65423", "金杯", 800, 16, "当前可租");
        vehicles[5] = new Bus("皖A65423", "金杯", 800, 16, "当前可租");
        vehicles[6] = new Bus("皖A52454", "金龙", 1500, 34, "当前可租");
        vehicles[7] = new Bus("皖A20221", "金龙", 1500, 34, "当前可租");
    }

    //查看车辆信息
    public void check() {
        System.out.println("<<<<车辆信息>>>>>");
        for (int i = 0; i < count; i++) {
            if (vehicles[i] != null) {
                vehicles[i].show();
            } else {
                break;
            }
        }
    }

    //租车
    public void rentcar() {
        System.out.println("请输入您的姓名");
        String name = input.next();
        System.out.println();
        System.out.println("请选择要租车的类型：（1.轿车 2:客车）");
        int choice = input.nextInt();
        for (int i = 0; i < count; i++) {
            if (!vehicles[i].getState().equals("当前可租")){
                System.out.println("您选择的车辆已租出");
            }else if (choice==1){
                if (vehicles[i] instanceof Car){
                    System.out.println(vehicles[i].getVehicleid()+" "+vehicles[i].getBrand()+" "+vehicles[i].getRent()+" "+vehicles[i].getState());
                }
            }else if (choice==2){
                if (vehicles[i] instanceof Bus){
                    System.out.println(vehicles[i].getVehicleid()+" "+vehicles[i].getBrand()+" "+vehicles[i].getRent()+" "+vehicles[i].getState());
                }
            }
        }
        System.out.println("请输入选择的车牌");
        String chepai=input.next();
        System.out.println("请输入租赁的天数");
        int day=input.nextInt();
        for (int i = 0; i < count; i++) {
            if (vehicles[i].getState().equals("当前可租")&&vehicles[i]!=null){
                if (vehicles[i].getVehicleid().equals(chepai)){
                    System.out.println("租赁成功");
                    System.out.println("租车的价格为"+vehicles[i].calcRent(day));
                    vehicles[i].setState("已租出");
                }

               rent[sum]=new Rent(name,chepai,vehicles[i].getBrand(),day,vehicles[i].calcRent(day));
                sum++;
            }
        }

    }
    //还车
    public void ruturncar(String carnumber){
        for (int i = 0; i <count ; i++) {
            if (vehicles[i].getState().equals("已租出")&&vehicles[i].getVehicleid().equals(carnumber)){
                vehicles[i].setState("当前可租");
                System.out.println("已还车");
                return;
            }
        }
        System.out.println("还车失败");

    }
    //报废车辆
    public boolean scrap(String carnumber){
        for (int i = 0; i <count ; i++) {
            if (vehicles[i].getVehicleid().equals(carnumber)){
                vehicles[i]=null;
                for (int j=i;j<count-1;j++){
                    vehicles[j]=vehicles[j+1];
                }
                vehicles[count-1]=null;
                count--;
                System.out.println("您选择的车辆已报废");
                return true;
            }
        }
        return false;
    }
    public void buy(){
        while (true){
            System.out.println("请选择要采购车辆的信息(1.轿车  2.客车)：");
            System.out.println("请选择：");
            int chioce=input.nextInt();
            System.out.println("请输入您要采购的车辆信息");
            System.out.println("<<<<<<<<<<<<<<<<");
            System.out.println("汽车车牌号");
            String number=input.next();
            System.out.println("汽车品牌");
            String brand=input.next();
            System.out.println("汽车价格");
            int price=input.nextInt();
            System.out.println("汽车可乘坐人数");
            int seat=input.nextInt();
            System.out.println("请输入汽车状态");
            String state=input.next();
            System.out.println("请输入汽车型号");
            String type=input.next();

            if (count>=20){
                System.out.println("车辆已满，无法购买");
            }
            if (chioce==1){
                vehicles[count]=new Car(number,brand,price,seat,state,type);
                count++;
                return;

            }
            if (chioce==2){
                vehicles[count]=new Car(number,brand,price,seat,state,type);
                count++;
                return;
            }
        }



    }
//显示租赁人信息
    public void showsum(){
        for (int i = 0; i <sum ; i++) {
            if (rent[i].getVehicleid().equals(vehicles[i].getVehicleid()))
           rent[i].show();
        }
    }
}